package api.User;

import com.alibaba.fastjson2.JSON;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/api/user/*")
public class GetUser extends HttpServlet {
    private final ImplUserUser implUser = new ImplUserUser();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        Map<String, Object> body = JSON.parseObject((String) req.getAttribute("body"));
        String uri = req.getRequestURI();
        if(uri.equals("/api/user/login")) resp.getWriter().write(implUser.login(body));
        if(uri.equals("/api/user/id"))resp.getWriter().write(implUser.getInfo(body.get("id").toString()));
        if(uri.equals("/api/user/add")) resp.getWriter().write(implUser.addUser(body.get("user").toString()));
    }
}
